<?php
/**
 *
 * @author 李大牛家的牛 (scafel@163.com)
 * @className admin_table.blade.php
 * @createDate 2025/7/31 - 13:13:23
 * @description
 **/
?>


@include('manage.default.template.header')
<div class="layui-fluid" style="padding-top: 10px;">
    <div class="layui-card">
        <table class="layui-hide" id="manage_rule_table" lay-filter="manage_rule_table"></table>
        <script type="text/html" id="manage_rule_table_row_action">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
</div>
@include('manage.default.template.footer')
<script>
    layui.use(['treeTable'], function () {
        var $ = layui.$,
            table = layui.treeTable ;
        table.render({
            elem:"#manage_rule_table",
            url:"/manage/system/rule/data",
            height: 'full-30',
            tree: {
                view: {
                    indent: 20,
                    showIcon: true,
                    showLine: true,
                    flexIconClose: "layui-icon layui-icon-triangle-r",
                    flexIconOpen: "layui-icon layui-icon-triangle-d",
                    dblClickExpand: false
                },
                customName: {
                    pid: "pCode",
                    name: "code",
                    id: "code",
                }
            },
            cols: [[
                {field: "code", width: 200, title: "编码", fixed: 'left'},
                {field: "ltar001", title: "菜单名称",},
                {field: "ltar002", title: "菜单路径",},
                {field: "ltar003", title: "菜单图标", templet: function (field) {
                    return `<i class="layui-icon layui-icon-${field.ltar003}"/>`;
                }},
                {title: "操作", width: 250, align: "center", fixed: "right", toolbar: "#manage_rule_table_row_action"}
            ]],
            text: {none: '加载数据为空'},
            parseData: function(res){ // res 即为原始返回的数据
                return {
                    "code": res.code === 1 ? 0 : 1, // 解析接口状态
                    "msg": res.msg, // 解析提示文本
                    "data": res.data.treeData // 解析数据列表
                };
            },
        });
        table.on("tool(manage_admin_table)",function (t) {
            const i = t.data;
            if (t.event === "del"){
                layer.confirm("确定删除此项？", function(e) {
                    let url = `/manage/system/rule/${i.code}/delete`;
                    req.get(url, {},function (res) {
                        layer.msg(res.msg);
                        table.reload('manage_admin_table'); //重载表格
                        layer.close(e)
                    })
                });
            }
            else{
                layer.msg("功能开发中");
            }
        });
    });
</script>
